<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root"></div>
    <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
 <script type="text/babel">
    let root = document.getElementById('root')
    class MyForm extends React.Component {
        constructor(props) {
            super(props)
            this.state = {username: '',happy: '',sex: ''}
            this.handle = this.handle.bind(this)
        }
        handle() {
            console.log(event.target.checked);
            // let val = event.target.name == 'happy' ? event.target.checked : event.target.value
        //   this.setState({username: event.target.value}) 
        }
        render() {
            return (
                <div>
                    <form action="">
                    <label>姓名：</label>
                    <input type="text" name="username" value={this.state.username} onChange={this.handle}/>
                    <label>性别：</label>
                    <select name="sex" value={this.state.sex} onChange={this.handle}>
                        <option value="">请选择</option>
                        <option value="1">男</option>    
                        <option value="2">女</option>    
                    </select>
                   <label >爱好</label>
                   <input type="checkbox" name="happy" value="1"  onChange={this.handle}/>篮球
                   <input type="checkbox" name="happy" value="2"  onChange={this.handle}/>足球
                    </form>
                <h3>{this.state.username}</h3>    
                </div>
            )
        }
    }
    
    ReactDOM.render(<MyForm name=""/>,root)
</script>
</body>
</html>